// PartFormatManager.h: interface for the PartFormatManager class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_PARTFORMATMANAGER_H__42086779_D92C_4A7B_8E0E_2421C7D66C9D__INCLUDED_)
#define AFX_PARTFORMATMANAGER_H__42086779_D92C_4A7B_8E0E_2421C7D66C9D__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxtempl.h>
#include "DBConnectionManager.h"
#include "JointPortFormersOfPartFormat.h"
#include "PropertiesOfProductFormat.h"
#include "ManagerTemplate.h"
#include "PartFormat.h"

class DSItem
{
public:
	DSItem() {}
	~DSItem() {}

public:
	const CString& Uri() const { return m_ScriptURI; }
	const CString Path() const {
			int iPos = Uri().ReverseFind ( _T ( '\\' ) );
			if ( iPos == -1 )
				return "";
			return Uri().Left( iPos+1 ); }
	const CString FileName() const {
			int iPos = Uri().ReverseFind ( _T ( '\\' ) );
			if ( iPos == -1 )
				return "";
			return Uri().Mid ( iPos + 1 ); }
	const CString& FormatName() const { return m_FormatName; }
	const CString& LegalCondition() const {return m_strLegalCondition;}
	_ConnectionPtr* Connection() const { return m_DataSourceConnection; }
	const CString& BmpName() const { return m_strBmpName;}
public:
	void Uri( const CString& uri ) { m_ScriptURI = uri; }
	void FormatName( const CString& fn ) { m_FormatName = fn; }
	void Connection( _ConnectionPtr* conn ) { m_DataSourceConnection = conn; }
	void LegalCondition(const CString& strCondition){
		m_strLegalCondition = strCondition;
	}
	void BmpName(const CString& strBmp){ m_strBmpName = strBmp;	}
private:
	CString m_ScriptURI;
	CString m_FormatName;
	CString m_strLegalCondition;
	_ConnectionPtr* m_DataSourceConnection;
	CString m_strBmpName;
};

class JointSystem::PartFormatManager;

class DSItemManager : public SameKeyManagerTemplate<CString, DSItem>
{
	friend class JointSystem::PartFormatManager;
private:
	DSItemManager(JointSystem::PartFormatManager* pfm );
	virtual ~DSItemManager();
	
private:
	bool Initialize( JointSystem::PartFormatManager* pfm );

public:
	Iterator* GetItem( const CString& pfid );
};
namespace JointSystem
{
class AFX_EXT_CLASS PartFormat  
{
public:
	PartFormat( PartFormatManager* pfm = 0 ) { m_Manager = pfm;
		m_JointPortFormers = 0; m_Properties = 0; }
	~PartFormat() { 
		if ( m_JointPortFormers ) delete m_JointPortFormers;
		if ( m_Properties ) delete m_Properties; }

public:
	_ConnectionPtr* DataSourceConnection();
	JointPortFormersOfPartFormat* GetJointPortFormers();
	DSItemManager::Iterator* GetDSItem();
	PropertiesOfProductFormat* GetProperties(); 

public:
	PartFormatManager* Manager() const { return m_Manager; }

public:
	friend class JointPart;
	const CString& ID() const { return m_ID; }

private:
	JointPortFormersOfPartFormat* JointPortFormers() { return m_JointPortFormers; }
	PropertiesOfProductFormat* Properties() const { return m_Properties; }

public:
	friend class PartFormatManager;
	void ID( const CString& id ) { m_ID = id; }
	void JointPortFormers( JointPortFormersOfPartFormat* jpfopf ) { m_JointPortFormers = jpfopf; }
	void Properties( PropertiesOfProductFormat* pop ) { m_Properties = pop; }
	void Manager( PartFormatManager* manager ) { m_Manager = manager; }

private:
	CString m_ID;
	PartFormatManager* m_Manager;
	JointPortFormersOfPartFormat* m_JointPortFormers;
	PropertiesOfProductFormat* m_Properties;
};
class ProductCatalog;

class AFX_EXT_CLASS PartFormatManager : public ManagerTemplate<CString, PartFormat> 
{
	friend class ProductCatalog;
	friend class PartFormat;
private:
	PartFormatManager( ProductCatalog* owner );
	~PartFormatManager();

private:
	PartFormat* GetPartFormat( const CString& partFormatID );
	JointPortFormersOfPartFormat* GetJointPortFormers( const CString& aPartFormatID );
	DSItemManager::Iterator* GetDSItem( const CString& pfid );
	PropertiesOfProductFormat* GetProperties( const CString& pfid );
	BOOL InitPropertyStack(INT nID, JointPortFormer* pFormer);

public:
	ProductCatalog* Owner() const { return m_Owner; }
public:
	_ConnectionPtr* DataSourceConnection();
	DSItemManager* GetDSItemManager();

private:
	 ProductCatalog* m_Owner;
	_ConnectionPtr* m_DSConn;
	DSItemManager* m_DSManager;
};

};


#endif // !defined(AFX_PARTFORMATMANAGER_H__42086779_D92C_4A7B_8E0E_2421C7D66C9D__INCLUDED_)
